/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUIComponents;

import java.awt.Container;
import javax.swing.*;
import MainClasses.*;
import MainClasses.Event.*;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 *
 * @author andrewcutler
 */
public class DeleteEventFrame extends JFrame{
    
    public DeleteEventFrame()
    {
        super("Delete Event");
        
        Container content = this.getContentPane();
        content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));
        if(main.getUserCourse().getEvents().size() == 0)
        {
            content.add(new JLabel("No Events to Delete."));
        }
        else
        {
            content.add(new JLabel("Events:"));
        }
        for(Event e : main.getUserCourse().getEvents())
        {
            content.add(new OwnEventPanel(e));
        }
        
        pack();
    }
    
    
    private class OwnEventPanel extends JPanel{
        
        private Event event;
        private JPanel panel;
        
        public OwnEventPanel(Event e)
        {
            event = e;
            panel = this;
            setLayout(new GridLayout(1,2));
            
            this.add(event.getStandardPanel());
            JButton delete = new JButton("Delete");
            delete.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e)
                {
                    Container parent = panel.getParent();
                    parent.remove(panel);
                    parent.validate();
                    main.getUserCourse().removeEvent(event);
                    
                }
            });
            this.add(delete);
        }
    }
}
